package com.nidu.demo.file.executor.command;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.cola.dto.Response;
import com.nidu.demo.file.gateway.FileConfigGateway;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Set;

/**
 * 文件配置删除命令执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class FileConfigDeleteCmdExe {

    private final FileConfigGateway gateway;

    @Transactional
    public Response execute(Long id) {
        if(id != null){
            gateway.deleteById(id);
        }
        return Response.buildSuccess();
    }

    @Transactional
    public Response execute(Set<Long> ids) {
        if(!CollUtil.isEmpty(ids)){
            gateway.deleteByIds(ids);
        }
        return Response.buildSuccess();
    }
}
